//
//  ShadowView.m
//  iOSStudy
//
//  Created by Evan Xie on 12/4/15.
//  Copyright © 2015 Family Wings. All rights reserved.
//

#import "ShadowView.h"

@implementation ShadowView

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetAllowsAntialiasing(context, true);
    CGContextSetShouldAntialias(context, true);
    
    CGContextSaveGState(context);
    
    // Draw first rect shadow.
    CGSize offset = {50, 20};
    CGContextSetShadowWithColor(context, offset, 20, [UIColor redColor].CGColor);
    
    CGRect squareRect = CGRectMake(60, 20, 150, 150);
    CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
    CGContextFillRect(context, squareRect);
    
    // Draw second rect shadow
    offset = (CGSize){50, -20};
    
    CGFloat color[4] = {0.8, 0.6, 0, 0.5};
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef shadowColor = CGColorCreate(colorSpace, color);
    CGContextSetShadowWithColor(context, offset, 10.0, shadowColor);
    CGColorRelease(shadowColor);
    CGColorSpaceRelease(colorSpace);
    
    squareRect = CGRectMake(60, 250, 150, 150);
    CGContextFillRect(context, squareRect);
    
    CGContextRestoreGState(context);
}

@end
